<template>
  <div id="newsList">
    <div class="containerset">
      <div class="news-list">
        <ul>
          <li v-for="item in newcon" v-bind:key="item.id">
            <div class="img">
              <img :src="item.urlImgCover">
            </div>
            <div class="info">
              <div class="tit">
                <router-link :to="{path:'/newsDetail',query:{ id: item.id != '' ? item.id: ''}}">{{item.titleNews}}</router-link>
              </div>
              <div class="tip">
                <router-link :to="{path:'/newsDetail',query:{ id: item.id != '' ? item.id: '' }}">{{item.subTitleNews}}</router-link>
              </div>
              <div class="more">
                <router-link :to="{path:'/newsDetail',query:{ id: item.id != '' ? item.id: '' }}">
                  详情
                </router-link>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="page" v-if="path=='/newcenter'">
        <el-pagination background layout="prev, pager, next" :page-size="pagesize" :total="total" @current-change="handleCurrentChange" ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import global from './global'
export default {
    data(){
      return {
        page:1,
        newcon:'',
        limit:3,
        total:0,
        pagesize:9,
        path:''
      }
    },
    methods:{
      handleCurrentChange(val) {
        var data ={};
        data = {
          page:`${val}`,
          limit:this.pagesize,
        }
        var url = global.apiGlobal + "contentNews/fa/home";
        this.$http.post(url, JSON.stringify(data)).then(function (data) {
          if(data.status == 200){
            this.newcon = data.body.content.rows;
            this.total = data.body.content.records;
          }
        }, function (response) {
          console.log(response)
        })
      }
    },
    mounted() {
      var data ={};
      this.path = this.$route.path;
      if(this.$route.path == "/"){
         data = {
          page:this.page,
          limit:this.limit
        }
      }else if(this.$route.path == "/newcenter"){
         data = {
          page:this.page,
          limit:this.pagesize,
        }
      }
      var url = global.apiGlobal + "contentNews/fa/home";
      this.$http.post(url, JSON.stringify(data)).then(function (data) {
        console.log(data)
        if(data.status == 200){
          this.newcon = data.body.content.rows;
          this.total = data.body.content.records;
        }
      }, function (response) {
        console.log(response)
      })
    }
  }
</script>

<style scoped>
  #newsList{
    width: 100%;
    min-width: 1200px;
  }

  .news-list {
    padding: 30px 0 30px 0
  }

  .news-list ul {
    display: flex;
    flex: auto;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }

  .news-list ul>li {
    background: #fff;
    margin: 15px 1%;
    overflow: hidden;
    width: 30%;
    float: left;
    border: 1px solid #ededed;
    border-radius: 10px;
  }

  .news-list ul>li:hover{
    box-shadow: 5px 5px 5px #f0f0f0;
  }

  .news-list ul>li a {
    display: block;
    color: #666
  }

  .news-list ul>li .img {
    margin: -1px;
    overflow: hidden;
    height: 250px;
  }

  .news-list ul>li .img img {
    display: block;
    width: 100%;
    height: 300px;
    display: block;
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out
  }

  .news-list ul>li .img:hover img {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1)
  }

  .news-list ul>li .info .tit a {
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis
  }

  .news-list ul>li .info {
    padding: 20px 20px 0
  }

  .news-list ul>li .tit {
    width: 100%;
    font-size: 20px;
    line-height: 20px;
    margin-bottom: 10px;
    color: #666;
    white-space: nowrap;
  }

  .news-list ul>li .tip {
    font-size: 12px;
    height: 45px;
    line-height: 2;
    color: #666;
    overflow: hidden;
    margin-bottom: 10px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .news-list ul>li .more {
    font-size: 12px;
    color: #666;
    border-top: 1px solid #ededed;
    height: 58px;
    line-height: 58px
  }

  .news-list ul>li .more:before {
    display: block;
    float: right;
    content: '+';
    width: 31px;
    height: 10px;
  }


  .news-view .title {
    position: relative;
    width: 100%;
    border-bottom: 1px solid #efefef;
    padding-bottom: 30px
  }

  .news-view .title .tit {
    font-size: 30px;
    line-height: 30px;
    color: #666;
    margin-bottom: 10px
  }

  .news-view .title .time {
    font-size: 12px;
    line-height: 18px;
    color: #999
  }

  .news-view .title .share {
    position: absolute;
    right: 0;
    bottom: 30px
  }

  .news-view .title .share .icon {
    display: block;
    float: left;
    margin-left: 8px;
    width: 28px;
    height: 28px;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border: 1px solid #ccc;

  }

  .news-view .title .share .icon:hover {
    cursor: pointer;
    border-color: #f8b62b
  }

  .news-view .title .share .icon-weibo {
    background-position: -97px -109px
  }

  .news-view .title .share .icon-wechat {
    background-position: -97px -140px
  }

  .news-view .content {
    padding: 30px 0
  }

  .page{
    text-align: center;
    margin: 40px auto;
  }
</style>
